package cn.zjnu.dao;

import cn.zjnu.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface LoginDao {
    /*
        添加用户
     */
    @Insert("INSERT INTO user_message values(null,#{username},#{password},null)")
    public int save(User user);
    /*
        修改用户信息
        目前提供修改用户名、密码的功能
     */
    @Update("UPDATE user_message SET password=#{password} WHERE username=#{username}")
    public int update(User user);
    /*
        删除用户
    */
    @Delete("DELETE FROM user_message WHERE id = #{id}")
    public int delete(Integer id);
    /*
        查询单个用户
        1. 按照id查询
        2. 按照用户名查询
        3. 按照用户名、密码对查询
    */
    @Select("SELECT * FROM user_message WHERE id = #{id}")
    public User SelectById(Integer id);
    @Select("SELECT * FROM user_message WHERE username = #{username}")
    public User SelectByUsername(User user);
    @Select("SELECT * FROM user_message WHERE username = #{username} AND password = #{password}")
    public User SelectByNamePassword(User user);

    /*
        查询所有用户
    */
    @Select("SELECT * FROM user_message")
    public List<User> getAll();
}
